package com.study.app.service.impl;

import com.study.app.service.IAppRemoteControlService;
import com.study.common.core.domain.R;
import com.study.common.fdfs.ImageUtil;
import com.study.common.utils.spring.SpringUtils;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

@Slf4j
@Service
public class AppRemoteControlServiceImpl implements IAppRemoteControlService {
    @Value("${listener.remote.control:#{null}}")
    private String remoteControlUrl;
//    private final HBaseDataService hBaseDataService = SpringUtils.getBean(HBaseDataService.class);

//    private final HBaseDataService hBaseDataService;

    private final RestTemplate restTemplate = SpringUtils.getBean(RestTemplate.class);
    @Override
    public Integer notifyControl(String deviceCode, Integer body, Integer attach) {
        //测试
//        String url =  "http://10.94.100.44:9089/instruct/body/control/"+ "1231231231231231" +"/" +1+"/"+1  ;
//        String url =  "http://10.94.100.44:9089/instruct/body/control/"+ "1231231231231231" ;
//        UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url);
//        builder.queryParam("body", 1);
//        builder.queryParam("attach", 1);
//         url = builder.toUriString();
//        NettyResult forObject = restTemplate.getForObject(url, NettyResult.class);
        //正式
        UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(remoteControlUrl+deviceCode);

        builder.queryParam("body", body);
        builder.queryParam("attach", attach);
        String url = builder.toUriString();

//        ResponseEntity<NettyResult> response = null;
//        response = restTemplate.getForEntity(url, NettyResult.class);
//        log.info("响应{}",response);
//        NettyResult res = response.getBody();
//
//        if (res.getCode() == 0 && (Integer)res.getData() == 1) {
//            return (Integer)res.getData();
//        }
        return 0;
    }

//    @Override
//    public R<?> getVehicleBodyParams(String deviceCode) {
//
//            List<AttributeName> attributeNames = Arrays.asList(
//                    AttributeName.seatLockStatus,
//                    AttributeName.tailBoxLockStatus,
//                    AttributeName.acc,
//                    AttributeName.gpsSignal,
//                    AttributeName.gsmSignal
//            );
//            AppVehicleStatusVo appVehicleStatusVo = new AppVehicleStatusVo();
//        try {
//                Map<AttributeName, AttributeInfo> attributeMap = hBaseDataService.lastAttributeToMap(deviceCode, attributeNames);
//                appVehicleStatusVo.setSeatLockStatus((Integer) attributeMap.get(AttributeName.seatLockStatus).getValue());
//                appVehicleStatusVo.setSeatLockStatus((Integer) attributeMap.get(AttributeName.tailBoxLockStatus).getValue());
//                appVehicleStatusVo.setSeatLockStatus((Integer) attributeMap.get(AttributeName.acc).getValue());
//                appVehicleStatusVo.setSeatLockStatus((Integer) attributeMap.get(AttributeName.gpsSignal).getValue());
//                appVehicleStatusVo.setSeatLockStatus((Integer) attributeMap.get(AttributeName.gsmSignal).getValue());
//
//            } catch (IOException e) {
//                System.out.println(e);
//                return R.fail();
//            }
//            return R.ok(appVehicleStatusVo);
//
//    }



}
